﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Framework.Infrastructure;
using System.Data.Entity;
using Framework.UnitOfWork;

namespace Framework.EntityFramework.Repositories
{
    public class DomainRepository : Framework.Repositories.DomainRepository
    {
        #region Construct
        /// <summary>
        /// Initializes a new instance of <c>Repository&lt;TAggregateRoot&gt;</c> class.
        /// </summary>
        /// <param name="context">The repository context being used by the repository.</param>
        public DomainRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
        {
           
        }
        #endregion

        public override int GenerateIdentity(string name = null)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = "Global";
            }
            int identity = (int)this.UnitOfWork.GetValueByKey<DbContext>("DomainModelContext")
                .Database.SqlQuery<decimal>(string.Format("insert into [{0}Identities] default values select SCOPE_IDENTITY()", name))
                .First();
            return identity;
        }

    }
}
